﻿
@inject IHttpService _httpService
@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService


<MDialog @bind-Value="Dialog"
         MaxWidth="600">
    <MDCard>

        <MCardText Class="pt-6">
            <CnGalWebSite.Shared.MasaComponent.Shared.Cards.Users.InfoCard Model="Model.User" Class="mb-2" Outline />

            @if (Model.Socres.IsScored)
            {
                <CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaRating Disable Value="(int)Model.Socres.TotalSocre" Label="总评" />
                <div class="label-large pb-2">
                    @($"音乐{Model.Socres.MusicSocre}分,美术{Model.Socres.PaintSocre}分,剧本{Model.Socres.ScriptSocre}分,演出{Model.Socres.ShowSocre}分,程序{Model.Socres.SystemSocre}分"+((isDubbing && Model.Socres.CVSocre > 0) ? $",配音{Model.Socres.CVSocre}分" : ""))
                </div>
            }

            @if (string.IsNullOrWhiteSpace(Model.PlayImpressions) == false)
            {
                <div class="title-medium" style="word-break: break-all; white-space: break-spaces;font-weight: 400;">评语：@Model.PlayImpressions</div>
            }
        </MCardText>

        @if (string.IsNullOrWhiteSpace(gameName) == false)
        {
            <MCardText Class="pb-2">
                @($"《{gameName}》")
            </MCardText>
        }
        <MCardText Class="@(gameId!=0?"pb-0":"")">
            @Model.LastEditTime.ToString("yyyy-MM-dd HH:mm:ss")
        </MCardText>

        @if (gameId != 0)
        {
            <MCardActions Class="pa-4 pt-0">
                <MSpacer></MSpacer>
                <CnGalWebSite.Components.Buttons.MasaButton Text="查看游戏" OnClick="@(()=>OnNav("/entries/index/" + gameId))" Icon="@IconType.Game.ToIconString()" Rounded />
            </MCardActions>
        }

    </MDCard>
</MDialog>


@code {

    public PlayedGameUserScoreModel Model { get; set; }

    bool Dialog { get; set; }

    int gameId = 0;
    string gameName;
    bool isDubbing;

    public void Refresh(bool dialog, PlayedGameUserScoreModel model, string _gameName = null, int _gameId = 0, bool _isDubbing = true)
    {
        gameId = _gameId;
        gameName = _gameName;
        Dialog = dialog;
        Model = model;
        isDubbing = _isDubbing;

        StateHasChanged();
        
    }


    public async Task OnNav(string url)
    {
        Dialog = false;
        await Task.Delay(1);
        NavigationManager.NavigateTo(url);
    }


}
